package com.fl.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MQconfig {

    //普通交换器
    private String direct_exchange = "direct_exchange";
    //死信交换机
    private String deal_exchange = "deal_exchange";
    //普通队列
    private String queue_name = "queue_name";
    //死信队列
    private String deal_routing_key = "deal_routing_name";

    @Bean
    private DirectExchange directExchange(){
        return new DirectExchange(direct_exchange);
    }
    @Bean
    private Queue directPayQueue(){
        Map<String,Object> map = new HashMap<>();
        map.put("x-dead-letter-exchange",deal_exchange);
        map.put("x-dead-letter-routing-key",deal_routing_key);
        //10秒过期
        map.put("x-message-ttl",10000);
        return new Queue(queue_name,true,false,false,map);
    }

    @Bean
    private Binding bindingOrderDirect() {
        return BindingBuilder.bind(directPayQueue()).to(directExchange()).with("OrderPay");
    }

}
